﻿let user = [
    {   
        id: 1,
        name: 'admin',
        password: '080425',
        avatar: '这是一个头像'
    }, {
        id: 2,
        name: 'l',
        password: '080425',
        avatar: '这是一个头像'
    }, {
        id: 3,
        name: 'i',
        nickname: 'TAO',
        avatar: '这是一个头像'
    }, {
        id: 4,
        name: 'n',
        password: '080425',
        avatar: '这是一个头像'
    },
]


let fn_login = (ctx, next) => {
    let username = ctx.request.body.username || ''
    let password = ctx.request.body.password || ''
    // console.log(ctx.request.body);
    // console.log(username);
    // console.log(password);
    let list = user.filter(item => {
        return item.name === username && item.password === password
    })
    let res;
    // console.log(list);
    if (list.length > 0) {
        res=ctx.body = {
            code:1000,
            data:list[0],
            msg:'登录成功'
        }
    } else {
        ctx.body = {
            code:404,
            data:'',
            msg:'账号或者密码错误，请重新输入'
        }
        res = '账号或者密码错误，请重新输入'
    }
    
}



module.exports = {
    'post /login': fn_login
}